package com.xb.report.controller;


import com.github.pagehelper.Page;
import com.xb.report.bean.PersonInfo;
import com.xb.report.service.IDemoService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * @Author gxd
 * jar运行 注意new modelAndView 开头没有/
 */

@Controller
@RequestMapping(value = "demo")
public class DemoController {
    @Autowired
    IDemoService demoService;


    Logger logger=LoggerFactory.getLogger(this.getClass());



    @RequestMapping(value = "/add")
    public @ResponseBody
    Map<String, Object> add(HttpServletRequest request, HttpServletResponse res) {
        res.setHeader("Access-Control-Allow-Origin", "*");
        ModelMap map = new ModelMap();
        Integer r = null;
        /*try {
            r = demoService.addInfo();
        } catch (Exception e) {
            logger.error(e.getMessage());
            //e.printStackTrace();
        }*/
        map.put("result", r);
        return map;
    }

    @RequestMapping(value = "/getListByPage")
    public @ResponseBody
    Map<String, Object> getList(HttpServletRequest request, HttpServletResponse res) {
        res.setHeader("Access-Control-Allow-Origin", "*");
        ModelMap map = new ModelMap();
        String text=request.getParameter("text");
        String date=request.getParameter("date");
        String type=request.getParameter("type");
        int pageNum= Integer.parseInt(request.getParameter("pageNum"));
        int pageSize=Integer.parseInt(request.getParameter("pageSize"));
        Page<PersonInfo> page =demoService.getListByPage(text, pageNum, pageSize);
        map.put("number", page.getTotal());
        map.put("pagesdata", page);
        return map;
    }

}
